<!--
 * @Author: 雷宇航
 * @Date: 2021-08-04 11:31:45
 * @LastEditTime: 2021-08-06 16:49:05
 * @LastEditors: 雷宇航
 * @Description: 
 * @FilePath: \icm-vue\src\views\hifar\contract\modules\ContractSalePurchaseApplyDetailModal.vue
-->

<template>
  <div v-if="mainId && list.length > 0">
    <a-tabs defaultActiveKey="1">
      <a-tab-pane :tab="index ? index + '、采购申请' : '采购申请'" key="1">
        <div>
          <a @click="edit">点击查看采购申请</a>
        </div>
        <j-modal
          :title="title"
          :width="1200"
          :visible="visible"
          :maskClosable="false"
          switchFullscreen
          @ok="handleOk"
          :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }"
          @cancel="handleCancel"
          cancelText="关闭"
        >
          <ContractSalePurchaseApplyDetail
            ref="realForm"
            @ok="submitCallback"
            :disabled="disableSubmit"
            :list="list"
            :index="index"
          />
        </j-modal>
      </a-tab-pane>
    </a-tabs>
  </div>
</template>
<script>
import ContractSalePurchaseApplyDetail from './ContractSalePurchaseApplyDetail'
import { getAction } from '@api/manage'

export default {
  name: 'ContractSalePurchaseApplyDetailModal',
  components: {
    ContractSalePurchaseApplyDetail,
  },
  props: {
    mainId: {
      type: String,
      default: '',
      required: false,
    },
    index: {
      type: Number,
    },
  },
  watch: {
    mainId: {
      immediate: true,
      handler(value) {
        if (value) {
          this.loadData(value)
        }
      },
    },
  },
  data() {
    return {
      title: '',
      width: 800,
      visible: false,
      disableSubmit: true,
      dataId: '',
      list: [],
      url: {
        list: '/contract/contractPurchaseApply/nonPermissionList',
      },
    }
  },
  mounted() {},
  methods: {
    loadData(value) {
      getAction(this.url.list, { saleId: value, pageNo: -1, pageSize: -1 }).then((res) => {
        if (res.success) {
          let data = []
          res.result.records.forEach((v, i) => {
            data.push(res.result.records.slice(i, i + 1))
          })
          this.list = data
        }
      })
    },
    add() {
      this.visible = true
      this.$nextTick(() => {
        this.$refs.realForm.add()
      })
    },
    edit(record) {
      this.visible = true
      // this.$nextTick(() => {
      //   this.$refs.realForm.edit(record)
      // })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      this.$refs.realForm.handleOk()
    },
    submitCallback() {
      this.$emit('ok')
      this.visible = false
    },
    handleCancel() {
      this.close()
    },
  },
}
</script>
